package org.snia.cdmi;

import java.util.ArrayList;
import java.util.List;

import org.snia.cdmi.locator.Node;
import org.snia.util.ConfigurableConstants;



/**
 * 系统常量设置
 * 
 * @author c90003207
 * 
 */
public class Constants extends ConfigurableConstants {
	static {
		init("config.properties");
		
		
	}
	/** 一致性hash的节点 */
	private static List<Node> LISTNODE = null;


	/** 分布式-i列表 */
	public static final String DISTRIBUTEDIP = getProperty("distributedIP", "");

	/** 本机内网ip */
	public static final String INTRANETIP = getProperty("intranetIp", "");

	/** 本机外网ip */
	public static final String EXTERIORIP = getProperty("exteriorIp", "");

	/** 容器元数据存储根目录 */
	public static final String MATA_CONTAINER_ROOT = getProperty("jcr.root", "D:/Metadata/.Container");

	/** 数据对象元数据存储根目录 */
	public static final String MATA_DATAOBJECT_ROOT = getProperty("jcr.root", "D:/Metadata/.DataObject");
	
	/** 数据块元数据存储根目录 */
	public static final String MATA_DATASLICE_ROOT = getProperty("jcr.root", "D:/Metadata/.DataSlice");

	/** 指定用户数据的存储根路径 */
	public static final String DATA_STORE_URL = "file:///D:/DataStore/.Data";
//	public static final String DATA_STORE_URL = "D:/DataStore/.Data";
	
	/** 域名 */
	public static final String DOMAIN = getProperty("domain", "");
	
	/**与云节点的端口*/
	public static final String CLOUDNODE_ICE_PORT= getProperty("cloudnode_ice_port", "");
	
	/**与管理的端口*/
	public static final String RESMGMT_ICE_PORT= getProperty("resmgmt_ice_port", "");
	
	/**
	 * 连接云节点端口
	 */
	public static final String CONNECT_CLOUDNODE_PORT=getProperty("connect_cloudnode_port", "");

	/** MINA端口 */
	public static final Integer MINAPORT = Integer.valueOf(getProperty("mima_port", "1023"));
	
	/**
	 * APP部署的相对PATH
	 */
	public static final String APP_SUBPATH = getProperty("appSubPath", "");

	/** Mina查询 */
	public static final String SEARCH = "search";

	/** MinaPUT */
	public static final String PUT = "put";

	/** Mina删除 */
	public static final String DETELE = "delete";

	/** Mina更新 */
	public static final String UPDATE = "update";

	/** 虚拟节点 */
	public static final Integer VIRTUAL_NODE_COUNT = 160;
	
	/**
	 * 单个刀片在线服务状态
	 */
	public static final Integer HOST_ONLINE = 1;
	
	/**
	 * 单个刀片离线服务状态
	 */
	public static final Integer HOST_OFFLINE = 0;
	
	
	/**
	 * 容器名称的最大值长度
	 */
	public static final Integer MAX_CONTAINER_NAME_LENGTH = 64;
	
	
    public static final String GROUP_IP = "239.1.1.1";
    
    
    /** 系统信息组播端口 */
    public static final int SYSTEM_INFO = 12123;
    
    /** CSP写入路径更新组播端口 */
    public static final int CSP_UPDATE = 12124;
    
    /** 删除文件索引组播端口 */
    public static final int INDEX_DEL = 12125;
    
    /** 重置索引文件组播端口 */
    public static final int INDEX_SEARCHER_INITAL = 12126;
    
    /** 应用配置更新组播端口 */
    public static final int APP_PROPERTIES = 12127;
    
    /**
     * 逗号分隔符
     */
    public static final String STRING_SPLIT_SEMICOLON = ";";
    
    /**
     * 等号的分割符
     */
    public static final String STRING_SPLIT_EQUALSIGN = "=";
    
    /**
     * 零字
     */
    public static final String DIGIT_STRING_ZERO = "0";

	
	/**
	 * 获得可存储的实际节点
	 * 
	 * @return
	 */
	public static synchronized List<Node> getListNode() {
		if (LISTNODE == null) {
			LISTNODE = new ArrayList<Node>();
			String ips[] = Constants.DISTRIBUTEDIP
					.split(";");
			for (String ip : ips) {
				LISTNODE.add(new Node(ip));
			}
		}
		return LISTNODE;
	}

	/**
	 * 重置LISTNODE
	 */
	public static void rest() {
		LISTNODE = null;
	}
	
    /** Default hostname for the S3 service endpoint */
    public static String S3_HOSTNAME = "s3.amazonaws.com";

    /** Service name for Amazon S3 */
    public static String S3_SERVICE_NAME = "Amazon S3";

    /** Default encoding used for text data */
    public static String DEFAULT_ENCODING = "UTF-8";

    /**
     * HMAC/SHA1 Algorithm per RFC 2104, used when signing S3 requests
     */
    public static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";

    /**
     * XML namespace URL used when sending S3 requests containing XML
     */
    public static final String XML_NAMESPACE = "http://s3.amazonaws.com/doc/2006-03-01/";

    /** Represents a null S3 version ID */
    public static final String NULL_VERSION_ID = "null";

    /**
     * The default size of the buffer when uploading data from a stream. A
     * buffer of this size will be created and filled with the first bytes from
     * a stream being uploaded so that any transmit errors that occur in that
     * section of the data can be automatically retried without the caller's
     * intervention.
     */
    public static final int DEFAULT_STREAM_BUFFER_SIZE = 128 * 1024;

    /**
     * HTTP status code indicating that preconditions failed and thus the
     * request failed.
     */
    public static final int FAILED_PRECONDITION_STATUS_CODE = 412;
}
